package com.goodving.guli.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.weight.BabyWeightUtil;

/**
 * Created by john on 2015/12/9.
 */
public class WeightTableView extends View {
    private static final String f9433a = "WeightTableView";
    private int f9434A;
    private String[][] f9435b;
    private Paint f9436c;
    private Paint f9437d;
    private Paint f9438e;
    private float f9439f;
    private Context f9440g;
    private int f9441h;
    private int f9442i;
    private int f9443j;
    private int f9444k;
    private int f9445l;
    private int f9446m;
    private int f9447n;
    private int f9448o;
    private int f9449p;
    private int f9450q;
    private int f9451r;
    private int f9452s;
    private int[] f9453t;
    private float f9454u;
    private float f9455v;
    private float f9456w;
    private float f9457x;
    private float f9458y;
    private int f9459z;

    public WeightTableView(Context context) {
        this(context, null);
    }

    public WeightTableView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f9454u = 23.3f;
        this.f9455v = 26.7f;
        this.f9456w = 23.3f;
        this.f9457x = 28.3f;
        this.f9458y = 36.6f;
        this.f9440g = context;
        this.f9436c = new Paint();
        this.f9436c.setColor(0xff000000);
        this.f9437d = new Paint();
        this.f9437d.setColor(0xff000000);
        this.f9437d.setTextSize((float) Utils.m7961a(10.0f, this.f9440g));
        this.f9437d.setAntiAlias(true);
        this.f9438e = new Paint();
        m14246a();
        m14248b();
    }

    private int m14245a(int i) {
        int mode = MeasureSpec.getMode(i);
        int size = MeasureSpec.getSize(i);
        this.f9459z = size;
        if (mode == 1073741824) {
            return size;
        }
        int paddingLeft = getPaddingLeft() + getPaddingRight();
        return mode == Integer.MIN_VALUE ? Math.min(paddingLeft, size) : paddingLeft;
    }

    private void m14246a() {
        this.f9441h = Color.parseColor("#b6b9bd");
        this.f9442i = Color.parseColor("#15b9d2");
        this.f9443j = Color.parseColor("#14b9af");
        this.f9444k = Color.parseColor("#14ba89");
        this.f9445l = Color.parseColor("#13ba46");
        this.f9446m = Color.parseColor("#8eb536");
        this.f9447n = Color.parseColor("#c8b129");
        this.f9448o = Color.parseColor("#faad19");
        this.f9449p = Color.parseColor("#f2f2f3");
        this.f9450q = Color.parseColor("#f8f8f8");
        this.f9451r = Color.parseColor("#898989");
        this.f9452s = Color.parseColor("#555555");
        this.f9453t = new int[]{this.f9441h, this.f9441h, this.f9442i, this.f9443j, this.f9444k, this.f9445l, this.f9446m, this.f9447n, this.f9448o};
    }

    private int m14247b(int i) {
        int mode = MeasureSpec.getMode(i);
        int size = MeasureSpec.getSize(i);
        this.f9434A = size;
        if (mode == 1073741824) {
            return size;
        }
        int paddingTop = getPaddingTop() + getPaddingBottom();
        return mode == Integer.MIN_VALUE ? Math.min(paddingTop, size) : paddingTop;
    }

    private void m14248b() {
        this.f9454u = Utils.m8026b(this.f9454u, this.f9440g);
        this.f9455v = Utils.m8026b(this.f9455v, this.f9440g);
        this.f9456w = Utils.m8026b(this.f9456w, this.f9440g);
        this.f9457x = Utils.m8026b(this.f9457x, this.f9440g);
        this.f9458y = Utils.m8026b(this.f9458y, this.f9440g);
        this.f9435b = BabyWeightUtil.m15905a().f11523a;
    }

    public void m14249a(String[][] strArr) {
        this.f9435b = strArr;
        invalidate();
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int length = this.f9435b.length;
        int length2 = this.f9435b[0].length;
        for (int i = 0; i < length; i++) {
            int i2 = 0;
            while (i2 < length2) {
                float f;
                float f2;
                float f3;
                float f4;
                if (i == 0) {
                    this.f9438e.setColor(this.f9453t[i2]);
                } else if (i2 == 0) {
                    this.f9438e.setColor(this.f9450q);
                } else if (i % 2 == 0) {
                    this.f9438e.setColor(this.f9449p);
                } else {
                    this.f9438e.setColor(this.f9450q);
                }
                if (i == 0) {
                    this.f9437d.setColor(-1);
                } else if (i2 == 0 || i2 == 1) {
                    this.f9437d.setColor(this.f9451r);
                } else {
                    this.f9437d.setColor(this.f9452s);
                }
                GuliLog.tracePrintInfo(f9433a, "mBgColorPaint " + this.f9438e.getColor());
                if (i == 0) {
                    if (i2 == 0 || i2 == 1) {
                        f = (((float) i2) * this.f9455v) + this.f9454u;
                        f2 = (((float) i) * this.f9456w) + this.f9454u;
                        f3 = (((float) (i2 + 1)) * this.f9455v) + this.f9454u;
                        f4 = (((float) (i + 1)) * this.f9456w) + this.f9454u;
                        canvas.drawRect(f, f2, f3, f4, this.f9438e);
                        canvas.drawLine(f, f2, f + this.f9455v, f2, this.f9436c);
                        canvas.drawLine(f, f2, f, f2 + this.f9456w, this.f9436c);
                    } else {
                        f = (2.0f * (this.f9455v - this.f9458y)) + (this.f9454u + (((float) i2) * this.f9458y));
                        f2 = (((float) i) * this.f9456w) + this.f9454u;
                        f3 = (2.0f * (this.f9455v - this.f9458y)) + (this.f9454u + (((float) (i2 + 1)) * this.f9458y));
                        f4 = (((float) (i + 1)) * this.f9456w) + this.f9454u;
                        canvas.drawRect(f, f2, f3, f4, this.f9438e);
                        canvas.drawLine(f, f2, f + this.f9458y, f2, this.f9436c);
                        canvas.drawLine(f, f2, f, f2 + this.f9456w, this.f9436c);
                    }
                } else if (i2 == 0 || i2 == 1) {
                    f = (((float) i2) * this.f9455v) + this.f9454u;
                    f2 = (this.f9456w - this.f9457x) + (this.f9454u + (((float) i) * this.f9457x));
                    f3 = (((float) (i2 + 1)) * this.f9455v) + this.f9454u;
                    f4 = (this.f9456w - this.f9457x) + (this.f9454u + (((float) (i + 1)) * this.f9457x));
                    canvas.drawRect(f, f2, f3, f4, this.f9438e);
                    canvas.drawLine(f, f2, f + this.f9455v, f2, this.f9436c);
                    canvas.drawLine(f, f2, f, f2 + this.f9457x, this.f9436c);
                } else {
                    f = (2.0f * (this.f9455v - this.f9458y)) + (this.f9454u + (((float) i2) * this.f9458y));
                    f2 = (this.f9456w - this.f9457x) + (this.f9454u + (((float) i) * this.f9457x));
                    f3 = (2.0f * (this.f9455v - this.f9458y)) + (this.f9454u + (((float) (i2 + 1)) * this.f9458y));
                    f4 = (this.f9456w - this.f9457x) + (this.f9454u + (((float) (i + 1)) * this.f9457x));
                    canvas.drawRect(f, f2, f3, f4, this.f9438e);
                    canvas.drawLine(f, f2, f + this.f9458y, f2, this.f9436c);
                    canvas.drawLine(f, f2, f, f2 + this.f9457x, this.f9436c);
                }
                canvas.drawText(this.f9435b[i][i2], ((f + f3) / 2.0f) - (this.f9437d.measureText(this.f9435b[i][i2]) / 2.0f), (f2 + f4) / 2.0f, this.f9437d);
                i2++;
            }
        }
        Canvas canvas2 = canvas;
        canvas2.drawLine(0.0f + this.f9454u, this.f9456w + (this.f9454u + (((float) (length - 1)) * this.f9457x)), (2.0f * this.f9455v) + (this.f9454u + (((float) (length2 - 2)) * this.f9458y)), this.f9456w + (this.f9454u + (((float) (length - 1)) * this.f9457x)), this.f9436c);
        canvas2 = canvas;
        canvas2.drawLine((2.0f * this.f9455v) + (this.f9454u + (((float) (length2 - 2)) * this.f9458y)), 0.0f + this.f9454u, (2.0f * this.f9455v) + (this.f9454u + (((float) (length2 - 2)) * this.f9458y)), this.f9456w + (this.f9454u + (((float) (length - 1)) * this.f9457x)), this.f9436c);
    }

    protected void onMeasure(int i, int i2) {
        m14247b(i2);
        int a = m14245a(i);
        this.f9439f = (((float) this.f9459z) - (this.f9454u * 2.0f)) / ((float) this.f9435b[0].length);
        setMeasuredDimension(a, (int) ((this.f9456w + (this.f9457x * ((float) (this.f9435b.length - 1)))) + (this.f9454u * 2.0f)));
        GuliLog.tracePrintInfo(f9433a, "onMeasure width " + this.f9459z + " and heght " + this.f9434A);
    }
}
